/**
 * @author casazaft
 */
Package("j2j.dom").Class("Template", {
    Template: function(str){
        if (typeof str != "string") 
            throw Error(this.getClass().getName() + " only accept string parameter");
        var m, i = 0, rp;
        var result = ["var fun=function(){var r =[];"];
        var mRe = this.mRe;
        while ((m = mRe.exec(str)) != null) {
            result.push('r.push("' + str.substring(i, m.index) + '");');
            i = m.index + m[1].length;
            rp = parseInt(m[2]);
            result.push("r.push(arguments[" + rp + "]);");
        }
        result.push('r.push("' + str.substring(i, str.length) + '");');
        result.push('return r.join("");}');
        result = result.join("");
        eval(result);
        return fun;
    },
    Prototype: {
        mRe: /(\{(\d+)\})/g
    }
});
